package com.lul15834.orderfood.activity.manager;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;
import com.lul15834.orderfood.R;
import com.lul15834.orderfood.activity.manager.fragment.ManagerHomeFragment;
import com.lul15834.orderfood.activity.manager.fragment.ManagerMyFragment;

public class Manager extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manager);
        FragmentManager fragmentManager=getSupportFragmentManager();
        FragmentTransaction transaction=fragmentManager.beginTransaction();
        //实现第一次访问加载的界面
        Intent intent=getIntent();
        String sta=intent.getStringExtra("sta");
        if(sta==null||sta.isEmpty()){
            transaction.replace(R.id.man_manager_frame,new ManagerHomeFragment());
            transaction.commit();
        }else {
            transaction.replace(R.id.man_manager_frame,new ManagerMyFragment());
            transaction.commit();
        }
        BottomNavigationView bottomNavigationView= findViewById(R.id.man_manager_bottom_menu);
        bottomNavigationView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                FragmentManager fragmentManager1=getSupportFragmentManager();
                FragmentTransaction transaction1=fragmentManager1.beginTransaction();
                int id=item.getItemId();
                if (id==R.id.man_manager_bottom_menu_home){
                    transaction1.replace(R.id.man_manager_frame,new ManagerHomeFragment());
                }
                if (id==R.id.man_manager_bottom_menu_add){
                    //跳转到新的界面
                    Intent intent=new Intent(Manager.this,ManagerAddFoodActivity.class);
                    startActivity(intent);
                    return  true;
                }
                if (id==R.id.man_manager_bottom_menu_my){
                    transaction1.replace(R.id.man_manager_frame,new ManagerMyFragment());
                }
                transaction1.commit();
                return true;
            }
        });
        //实现搜索功能
    }
}